#include <stdint.h>
#include <string.h>
#include <stdlib.h>

#include <rtthread.h>
#include <rtdevice.h>
#include "device_adc.h"
#define ADC_CHANNEL_MAX		(8) /* 0-7 */

rt_err_t convert(struct rt_device *device, int channel, int *value)
{
	rt_err_t result = RT_EOK;

	if(channel > (ADC_CHANNEL_MAX - 1))
	{
		result = -RT_EIO;
		goto _exit;
	}

	*value = (channel << 8) | (rand() % 0xFF); /* ch=4, return: 0x4xx */

_exit:
	return result;
}

static const struct rt_adc_ops adc_ops =
{
	convert,
};

 
int rt_hw_adc_init(void)
{
    int ret = RT_EOK;
	
	/* add ADC initial. */ 

    ret = rt_device_adc_create("adc", &adc_ops, RT_NULL);
 
    return ret;
}
INIT_DEVICE_EXPORT(rt_hw_adc_init);
